//
//  JieXiaoDetailCell.swift
//  HappyEat
//
//  Created by ctx2016 on 17/1/18.
//  Copyright © 2017年 陌路是我. All rights reserved.
//

import UIKit

class JieXiaoDetailCell: UITableViewCell {
    
    var nameLabel:UILabel = UILabel.init()
    
    var addNameLabel:UILabel = UILabel.init()
    
    var tagLabel:UILabel = UILabel.init()
    
    var qhLabel:UILabel = UILabel.init()
    
    var bottomView:UIView = UIView.init()
    
    var detailModel:ProductDetailModel?{
        didSet{
//            cell.addNameLabel.text = self.detailModel?.storeName
//            cell.nameLabel.text = self.model?.productName
//            if self.detailModel?.status == "1"{
//                cell.tagLabel.text = "众筹中"
//            }else if self.detailModel?.status == "2"{
//                cell.tagLabel.text = "待揭晓"
//            }else{
//                cell.tagLabel.text = "已揭晓"
//            }
//            cell.qhLabel.text = "期号:" + (self.model?.seriesCode ?? "")
            self.addNameLabel.text = self.detailModel?.storeName
            self.nameLabel.text = self.detailModel?.productName
            if self.detailModel?.status == "1" {
                self.tagLabel.text = "众筹中"
            }else if self.detailModel?.status == "2" {
                self.tagLabel.text = "待揭晓"
            }else
            {
                self.tagLabel.text = "已揭晓"
            }
            self.qhLabel.text = "期号:" + (self.detailModel?.seriesCode ?? "")
            //布局设置
            print(self.detailModel?.productName)
            let height:CGFloat = self.nameLabel.jqGetHeightWithstr(self.detailModel?.productName ?? "", withfontSize: 16, withLineSpace: 0, withmaxWidth: k_Wide - 32)
            self.nameLabel.snp.removeConstraints()
            self.nameLabel.snp.makeConstraints { (make) in
                make.left.equalTo(16)
                make.right.equalTo(-16)
                make.top.equalTo(12)
                make.height.equalTo(height)
            }
            self.addNameLabel.snp.makeConstraints { (make) in
                make.left.equalTo(16)
                make.top.equalTo(self.nameLabel.snp.bottom).offset(8)
                make.right.equalTo(-16)
                make.height.equalTo(12)
            }
            let width:CGFloat = self.tagLabel.width(forText: self.tagLabel.text ?? "", withFontSize: 14, withTextHeight: 14)
            self.tagLabel.snp.makeConstraints { (make) in
                make.left.equalTo(16)
                make.width.equalTo(width)
                make.height.equalTo(14)
                make.top.equalTo(self.addNameLabel.snp.bottom).offset(8)
            }
            self.qhLabel.snp.makeConstraints { (make) in
                make.left.equalTo(self.tagLabel.snp.right).offset(8)
                make.right.equalTo(-16)
                make.height.equalTo(14)
                make.top.equalTo(self.tagLabel)
            }
            self.bottomView.snp.makeConstraints { (make) in
                make.left.equalTo(0)
                make.right.equalTo(0)
                make.bottom.equalTo(0)
                make.height.equalTo(0.5)
            }
        }
    }
    
//    var dataDic:[String:String]?{
//        didSet{
//            //布局设置
//            self.nameLabel.snp.makeConstraints { (make) in
//                make.left.equalTo(16)
//                make.right.equalTo(-16)
//                make.top.equalTo(0)
//                make.height.equalTo(16)
//            }
//            self.addNameLabel.snp.makeConstraints { (make) in
//                make.left.equalTo(16)
//                make.top.equalTo(self.nameLabel.snp.bottom).offset(8)
//                make.right.equalTo(-16)
//                make.height.equalTo(12)
//            }
//            let width:CGFloat = self.tagLabel.width(forText: self.tagLabel.text ?? "", withFontSize: 14, withTextHeight: 14)
//            self.tagLabel.snp.makeConstraints { (make) in
//                make.left.equalTo(16)
//                make.width.equalTo(width)
//                make.height.equalTo(14)
//                make.top.equalTo(self.addNameLabel.snp.bottom).offset(8)
//            }
//            self.qhLabel.snp.makeConstraints { (make) in
//                make.left.equalTo(self.tagLabel.snp.right).offset(8)
//                make.right.equalTo(-16)
//                make.height.equalTo(14)
//                make.top.equalTo(self.tagLabel)
//            }
//            self.bottomView.snp.makeConstraints { (make) in
//                make.left.equalTo(0)
//                make.right.equalTo(0)
//                make.bottom.equalTo(0)
//                make.height.equalTo(0.5)
//            }
//        }
//    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

}
extension JieXiaoDetailCell{
    func setUI(){
       self.contentView.addSubview(self.nameLabel)
        self.contentView.addSubview(self.addNameLabel)
        self.contentView.addSubview(self.tagLabel)
        self.contentView.addSubview(self.qhLabel)
        self.contentView.addSubview(self.bottomView)
        self.bottomView.backgroundColor = .lightGray
        self.nameLabel.font = UIFont.systemFont(ofSize: 16)
        self.nameLabel.numberOfLines = 0
        self.addNameLabel.font = UIFont.systemFont(ofSize: 12)
        self.tagLabel.font = UIFont.systemFont(ofSize: 12)
        self.tagLabel.layer.cornerRadius = 4.0
        self.tagLabel.backgroundColor = .red
        self.tagLabel.textColor = .white
        self.qhLabel.font = UIFont.systemFont(ofSize: 14)
        self.tagLabel.textAlignment = .center
    }
}
